package com.neiquan.secondhand.exception;

import java.util.HashMap;

/**
 * 统一异常入口
 * @author wangz
 */
public class ResponseException extends RuntimeException{
	private static final long serialVersionUID = -1987893928694143596L;
	/** 默认错误码**/
	public final static int RESP_CODE_DEFAULT = 500;
	/** 其他未知错误**/
	public final static int RESP_CODE_OTHER = 599;
	/** 常规异常信息**/
	public static HashMap<Integer,String> exceptions = new HashMap<Integer,String>();
	/**
	 * 初始化code异常信息
	 */
	static {
		exceptions.put(401, "授权已过期");
	} 
	
	
	public ResponseException() {
		super();
	}
	public ResponseException(int code) {
		super("{\"code\":"+code+",\"message\":\""+exceptions.get(code)+"\"}");
	}
	public ResponseException(String message) {
		super("{\"code\":"+RESP_CODE_DEFAULT+",\"message\":\""+message+"\"}");
	}
	public ResponseException(int code,String message) {
		super("{\"code\":"+code+",\"message\":\""+message+"\"}");
	}
	public ResponseException(String message, Throwable ex) {
		super(message,ex);
	}
}
